import { useCallback, useRef } from "react";

export default function useChannelScroll() {
  const scrollContainerRef = useRef<HTMLDivElement | null>(null);
  const scrollHandler = useCallback((target: HTMLDivElement) => {
    // 如果滚动父级不存在, 阻止程序继续运行
    if (scrollContainerRef.current === null) return;
    const width = window.innerWidth;
    scrollContainerRef.current?.scrollTo({
      left:
        target.offsetLeft +
        target.offsetWidth / 2 -
        (width - width * 0.2373) / 2,
      behavior: "smooth",
    });
  }, []);
  return { scrollContainerRef, scrollHandler };
}
